﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Web.Mvc;

namespace Lilium.Web.Mvc.AjaxControlToolkit
{
	/// <summary>
	/// PopupControl extender
	/// </summary>
	[RequiredResource(typeof(PopupExtender))]
	[RequiredResource(typeof(CommonToolkitScripts))]
	[ToolkitScriptReference("PopupControl.PopupControlBehavior.js", LoadOrder = 1)]
	public class PopupControlExtender: DynamicPopulateExtenderControlBase
	{
		public PopupControlExtender(string elementID)
			: base("AjaxControlToolkit.PopupControlBehavior", elementID)
		{
		}

		public static void Commit(AjaxHelper ajaxHelper, string elementID, string result)
		{
			if (ajaxHelper == null)
				throw new ArgumentNullException("ajaxHelper");

			ajaxHelper.RegisterDataItem(elementID, result);
		}

		public static void Cancel(AjaxHelper ajaxHelper, string elementID)
		{
			if (ajaxHelper == null)
				throw new ArgumentNullException("ajaxHelper");

			ajaxHelper.RegisterDataItem(elementID, "$$CANCEL$$");
		}

		#region public string ExtenderControlID

		private string m_ExtenderControlID;

		[Browsable(false)]
		[EditorBrowsable(EditorBrowsableState.Never)]
		[SuppressMessage("Microsoft.Naming", "CA1706:ShortAcronymsShouldBeUppercase", Justification = "Following ASP.NET AJAX pattern")]
		public string ExtenderControlID { [DebuggerNonUserCodeAttribute] get { return m_ExtenderControlID ?? string.Empty; } [DebuggerNonUserCodeAttribute] set { m_ExtenderControlID = value; } }

		#endregion

		#region public string PopupControlID

		private string m_PopupControlID;

		/// <summary>
		/// ID of the control that pops up
		/// </summary>
		[ExtenderControlProperty]
		//[IDReferenceProperty(typeof(WebControl))]
		[RequiredProperty]
		[DefaultValue("")]
		[SuppressMessage("Microsoft.Naming", "CA1706:ShortAcronymsShouldBeUppercase", Justification = "Following ASP.NET AJAX pattern")]
		public string PopupControlID { [DebuggerNonUserCodeAttribute] get { return m_PopupControlID ?? string.Empty; } [DebuggerNonUserCodeAttribute] set { m_PopupControlID = value; } }

		#endregion

		#region public string CommitProperty

		private string m_CommitProperty;

		/// <summary>
		/// Optional name of the target control's property to set with the result of the popup
		/// </summary>
		/// <remarks>
		/// If not present, the default "value" property will be used
		/// </remarks>
		[ExtenderControlProperty]
		[DefaultValue("")]
		public string CommitProperty { [DebuggerNonUserCodeAttribute] get { return m_CommitProperty ?? string.Empty; } [DebuggerNonUserCodeAttribute] set { m_CommitProperty = value; } }

		#endregion

		#region public string CommitScript

		private string m_CommitScript;

		/// <summary>
		/// Optional script to run after setting the target control's property
		/// </summary>
		/// <remarks>
		/// Allows more complicated actions to be performed based on the popup results
		/// </remarks>
		[ExtenderControlProperty]
		[DefaultValue("")]
		public string CommitScript { [DebuggerNonUserCodeAttribute] get { return m_CommitScript ?? ""; } [DebuggerNonUserCodeAttribute] set { m_CommitScript = value; } }

		#endregion

		#region public PopupControlPopupPosition Position

		private PopupControlPopupPosition m_Position = PopupControlPopupPosition.Center;

		/// <summary>
		/// Optional position for the popup window (relative to the target control)
		/// </summary>
		[ExtenderControlProperty]
		[DefaultValue(PopupControlPopupPosition.Center)]
		public PopupControlPopupPosition Position { [DebuggerNonUserCodeAttribute] get { return m_Position; } [DebuggerNonUserCodeAttribute] set { m_Position = value; } }

		#endregion

		#region public int OffsetX

		private int m_OffsetX;

		/// <summary>
		/// Optional X (horizontal) offset for the popup window (relative to the target control)
		/// </summary>
		[ExtenderControlProperty]
		[DefaultValue(0)]
		public int OffsetX { [DebuggerNonUserCodeAttribute] get { return m_OffsetX; } [DebuggerNonUserCodeAttribute] set { m_OffsetX = value; } }

		#endregion

		#region public int OffsetY

		private int m_OffsetY;

		/// <summary>
		/// Optional Y (vertical) offset for the popup window (relative to the target control)
		/// </summary>
		[ExtenderControlProperty]
		[DefaultValue(0)]
		public int OffsetY { [DebuggerNonUserCodeAttribute] get { return m_OffsetY; } [DebuggerNonUserCodeAttribute] set { m_OffsetY = value; } }

		#endregion

		#region public Animation OnShow

		private Animation m_OnShow;

		/// <summary>
		/// OnShow animation
		/// </summary>
		[ExtenderControlProperty]
		[ClientPropertyName("onShow")]
		[Browsable(false)]
		[DefaultValue(null)]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		public Animation OnShow { [DebuggerNonUserCodeAttribute] get { return m_OnShow; } [DebuggerNonUserCodeAttribute] set { m_OnShow = value; } }

		#endregion

		#region public Animation OnHide

		private Animation m_OnHide;

		/// <summary>
		/// OnHide animation
		/// </summary>
		[ExtenderControlProperty]
		[ClientPropertyName("onHide")]
		[Browsable(false)]
		[DefaultValue(null)]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		public Animation OnHide { [DebuggerNonUserCodeAttribute] get { return m_OnHide; } [DebuggerNonUserCodeAttribute] set { m_OnHide = value; } }

		#endregion
	}
}